
#import "GetUserPassKeyRequest.h"

@implementation GetUserPassKeyRequest

//
// mail address
//
@synthesize mailAddress														= _mailAddress;

//
// pass key
//
@synthesize passKey															= _passKey;

//
// user id
//
@synthesize userId															= _userId;

//
// init
//
- (id)init
{
	//
	// call super
	
	//
	self																	= [super init];
	if(!self)
		return nil;
	
	//
	// create xml parser
	//
	self.xmlParser															= [[[XmlParser alloc] init] autorelease];
	self.relPath															= @"usercp.php";
	
	return self;
}

//
// dealloc
//
- (void)dealloc
{
	self.mailAddress														= nil;
	self.passKey															= nil;
	
	[super dealloc];
}

//
// finished
//
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
	if(self.response.statusCode == 200)
	{
		[self.xmlParser parseDocumentData:self.dataBuffer htmlMode:YES];
		self.mailAddress													= [self.xmlParser stringFromPath:@"//td[@id='outer']/table[@class='main']/following-sibling::table[1]/tr[2]/td[2]" startNode:0];
		if([[self.xmlParser stringFromPath:@"//td[@id='outer']/table[@class='main']/following-sibling::table[1]/tr[4]/td[1]" startNode:0] isEqualToString:@"Avatar"])
			self.passKey													= [self.xmlParser stringFromPath:@"//td[@id='outer']/table[@class='main']/following-sibling::table[1]/tr[5]/td[2]" startNode:0];
		else
			self.passKey													= [self.xmlParser stringFromPath:@"//td[@id='outer']/table[@class='main']/following-sibling::table[1]/tr[4]/td[2]" startNode:0];
		NSString* temp														= [self.xmlParser stringFromPath:@"//table[@id='info_block']/tr[1]/td[1]/table[1]/tr[1]/td[1]/span[1]/span[1]/a[1]/@href" startNode:0];
		self.userId															= [[temp substringFromIndex:19] integerValue];
	}
	
	[super connectionDidFinishLoading:connection];
}

@end
